package cn.kmsoft.common;


import java.io.Serializable;

/**
 * 统一返回数据结构v3.0-基于泛型封装
 *
 * @param <T>
 */
public class RespInfoEx<T>  implements Serializable {

    private Integer code;
    private String message;
    private String status;
    private T data;

    public RespInfoEx() { }
    public RespInfoEx(String status, Integer code, String message, T data) {
        this.status=status;
        this.code=code;
        this.message=message;
        this.data=data;
    }

    public static <T> RespInfoEx<T> instance(Integer code, String message, T data) {
        RespInfoEx<T> result = new RespInfoEx<>();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);

        return result;
    }

    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }

    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }
    public void setData(T data) {
        this.data = data;
    }



    public static <T> RespInfoEx<T> success(T data) {
        return new RespInfoEx<>(ResultEnum.SUCCESS.getStatus(), ResultEnum.SUCCESS.getCode(), ResultEnum.SUCCESS.getMessage(), data);
    }
    public static <T> RespInfoEx<T> success(String message, T data) {
        return new RespInfoEx<T>(ResultEnum.SUCCESS.getStatus(), ResultEnum.SUCCESS.getCode(), message, data);
    }

    public static RespInfoEx<?> failed() {
        return new RespInfoEx<>(ResultEnum.SUCCESS.getStatus(), ResultEnum.COMMON_FAILED.getCode(), ResultEnum.COMMON_FAILED.getMessage(), null);
    }
    public static RespInfoEx<?> failed(String message) {
        return new RespInfoEx<>(ResultEnum.SUCCESS.getStatus(),ResultEnum.COMMON_FAILED.getCode(), message, null);
    }
    public static RespInfoEx<?> failed(IResult errorResult) {
        return new RespInfoEx<>(ResultEnum.SUCCESS.getStatus(),errorResult.getCode(), errorResult.getMessage(), null);
    }



}
